/*   1:    */ package org.intellij.images.actions;
/*   2:    */ 
/*   3:    */

import com.intellij.execution.ExecutionException;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.execution.util.ExecUtil;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.EnvironmentUtil;
import org.intellij.images.ImagesBundle;
import org.intellij.images.fileTypes.ImageFileTypeManager;
import org.intellij.images.options.Options;
import org.intellij.images.options.OptionsManager;
import org.intellij.images.options.impl.OptionsConfigurabe;

import java.io.File;
import java.util.Iterator;
import java.util.Map;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */
/*  18:    */
/*  19:    */
/*  20:    */
/*  21:    */
/*  22:    */
/*  23:    */
/*  24:    */
/*  25:    */
/*  26:    */
/*  27:    */
/*  28:    */ 
/*  29:    */ public final class EditExternallyAction
/*  30:    */   extends AnAction
/*  31:    */ {
/*  32:    */   public void actionPerformed(AnActionEvent paramAnActionEvent)
/*  33:    */   {
/*  34: 51 */     Project localProject = (Project)paramAnActionEvent.getData(CommonDataKeys.PROJECT);
/*  35: 52 */     VirtualFile[] arrayOfVirtualFile1 = (VirtualFile[])paramAnActionEvent.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
/*  36: 53 */     Options localOptions = OptionsManager.getInstance().getOptions();
/*  37: 54 */     String str1 = localOptions.getExternalEditorOptions().getExecutablePath();
/*  38: 55 */     if (StringUtil.isEmpty(str1))
/*  39:    */     {
/*  40: 56 */       Messages.showErrorDialog(localProject, ImagesBundle.message("error.empty.external.editor.path", new Object[0]), ImagesBundle.message("error.title.empty.external.editor.path", new Object[0]));
/*  41:    */       
/*  42:    */ 
/*  43: 59 */       OptionsConfigurabe.show(localProject);
/*  44:    */     }
/*  45: 62 */     else if (arrayOfVirtualFile1 != null)
/*  46:    */     {
/*  47: 63 */       Map localMap = EnvironmentUtil.getEnvironmentMap();
/*  48: 64 */       for (Object localObject1 = localMap.keySet().iterator(); ((Iterator)localObject1).hasNext();)
/*  49:    */       {
/*  50: 64 */         localObject2 = (String)((Iterator)localObject1).next();
/*  51: 65 */         if (SystemInfo.isWindows) {
/*  52: 66 */           str1 = StringUtil.replace(str1, "%" + (String)localObject2 + "%", (String)localMap.get(localObject2), true);
/*  53:    */         } else {
/*  54: 69 */           str1 = StringUtil.replace(str1, "${" + (String)localObject2 + "}", (String)localMap.get(localObject2), false);
/*  55:    */         }
/*  56:    */       }
/*  57: 72 */       str1 = FileUtil.toSystemDependentName(str1);
/*  58: 73 */       localObject1 = new File(str1);
/*  59: 74 */       Object localObject2 = new GeneralCommandLine();
/*  60: 75 */       String str2 = ((File)localObject1).exists() ? ((File)localObject1).getAbsolutePath() : str1;
/*  61: 76 */       if (SystemInfo.isMac)
/*  62:    */       {
/*  63: 77 */         ((GeneralCommandLine)localObject2).setExePath(ExecUtil.getOpenCommandPath());
/*  64: 78 */         ((GeneralCommandLine)localObject2).addParameter("-a");
/*  65: 79 */         ((GeneralCommandLine)localObject2).addParameter(str2);
/*  66:    */       }
/*  67:    */       else
/*  68:    */       {
/*  69: 81 */         ((GeneralCommandLine)localObject2).setExePath(str2);
/*  70:    */       }
/*  71: 84 */       ImageFileTypeManager localImageFileTypeManager = ImageFileTypeManager.getInstance();
/*  72: 85 */       for (VirtualFile localVirtualFile : arrayOfVirtualFile1) {
/*  73: 86 */         if ((localVirtualFile.isInLocalFileSystem()) && (localImageFileTypeManager.isImage(localVirtualFile))) {
/*  74: 87 */           ((GeneralCommandLine)localObject2).addParameter(VfsUtilCore.virtualToIoFile(localVirtualFile).getAbsolutePath());
/*  75:    */         }
/*  76:    */       }
/*  77: 90 */       ((GeneralCommandLine)localObject2).setWorkDirectory(new File(str1).getParentFile());
/*  78:    */       try
/*  79:    */       {
/*  80: 93 */         ((GeneralCommandLine)localObject2).createProcess();
/*  81:    */       }
/*  82:    */       catch (ExecutionException localExecutionException)
/*  83:    */       {
/*  84: 96 */         Messages.showErrorDialog(localProject, localExecutionException.getLocalizedMessage(), ImagesBundle.message("error.title.launching.external.editor", new Object[0]));
/*  85: 97 */         OptionsConfigurabe.show(localProject);
/*  86:    */       }
/*  87:    */     }
/*  88:    */   }
/*  89:    */   
/*  90:    */   public void update(AnActionEvent paramAnActionEvent)
/*  91:    */   {
/*  92:104 */     super.update(paramAnActionEvent);
/*  93:    */     
/*  94:106 */     doUpdate(paramAnActionEvent);
/*  95:    */   }
/*  96:    */   
/*  97:    */   static void doUpdate(AnActionEvent paramAnActionEvent)
/*  98:    */   {
/*  99:110 */     VirtualFile[] arrayOfVirtualFile = (VirtualFile[])paramAnActionEvent.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
/* 100:111 */     boolean bool = a(arrayOfVirtualFile);
/* 101:112 */     if (paramAnActionEvent.getPlace().equals("ProjectViewPopup")) {
/* 102:113 */       paramAnActionEvent.getPresentation().setVisible(bool);
/* 103:    */     } else {
/* 104:116 */       paramAnActionEvent.getPresentation().setEnabled(bool);
/* 105:    */     }
/* 106:    */   }
/* 107:    */   
/* 108:    */   private static boolean a(VirtualFile[] paramArrayOfVirtualFile)
/* 109:    */   {
/* 110:121 */     boolean bool1 = false;
/* 111:122 */     if (paramArrayOfVirtualFile != null)
/* 112:    */     {
/* 113:123 */       ImageFileTypeManager localImageFileTypeManager = ImageFileTypeManager.getInstance();
/* 114:124 */       for (VirtualFile localVirtualFile : paramArrayOfVirtualFile)
/* 115:    */       {
/* 116:125 */         boolean bool2 = localImageFileTypeManager.isImage(localVirtualFile);
/* 117:126 */         bool1 |= bool2;
/* 118:127 */         if ((!localVirtualFile.isInLocalFileSystem()) || (!bool2)) {
/* 119:128 */           return false;
/* 120:    */         }
/* 121:    */       }
/* 122:    */     }
/* 123:132 */     return bool1;
/* 124:    */   }
/* 125:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.intellij.images.actions.EditExternallyAction

 * JD-Core Version:    0.7.0.1

 */